import cv2
import time
import requests
import os

cap = cv2.VideoCapture(0, cv2.CAP_DSHOW)
ret, frame = cap.read()
WIDTH = frame.shape[1]
HEIGHT = frame.shape[0]
FILENAME = "1.mp4"
FPS = 24
cap.set(cv2.CAP_PROP_FPS, 24)
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
out = cv2.VideoWriter(FILENAME, fourcc=fourcc, fps=FPS, frameSize=(WIDTH, HEIGHT))
time_end = time.time() + 5
while True:
    ret, frame = cap.read()
    if not ret:
        print("error")
        break
    ret = out.write(frame)
    if time.time() > time_end:
        break
out.release()
cap.release()

# url = "http://207.148.93.42:5000//test"
url = "http://127.0.0.1:5000//test"
files = {"file": open("1.mp4", "rb")}
requests.post(url=url, files=files)
files["file"].close()
os.remove("1.mp4")
